cmake_minimum_required(VERSION 3.10)
project(T_DT_2026_OpenCV_Advanced)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Allow user to pass OpenCV directory via -DOpenCV_DIR="path" or via environment variable OpenCV_DIR
if(NOT DEFINED OpenCV_DIR)
    if(DEFINED ENV{OpenCV_DIR})
        set(OpenCV_DIR $ENV{OpenCV_DIR})
    endif()
endif()

message(STATUS "OpenCV_DIR (CMake variable or env): ${OpenCV_DIR}")

find_package(OpenCV REQUIRED)

if(NOT OpenCV_FOUND)
    message(FATAL_ERROR "OpenCV not found. Please set -DOpenCV_DIR to the folder containing OpenCVConfig.cmake or set the environment variable OpenCV_DIR. Example: cmake -S . -B build -DOpenCV_DIR=\"D:/Tools/Cpp/OpenCV-MinGW-Build-OpenCV-4.5.5-x64/x64/mingw/lib/cmake/opencv4\"")
endif()

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/include
    ${OpenCV_INCLUDE_DIRS}
)

# 主程序
add_executable(main 
    src/main.cpp
    src/armor_detector.cpp
    src/number_classifier.cpp
    src/pnp_solver.cpp
    src/target_tracker.cpp
)

target_link_libraries(main ${OpenCV_LIBS})

# 训练程序
add_executable(train_svm 
    src/train_main.cpp
    src/svm_trainer.cpp
)

target_link_libraries(train_svm ${OpenCV_LIBS})

# 创建必要的目录
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/models)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dataset/train)